﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Elderos.Utils
{
    public class Token : Interval<int>
    {

        private string _word;
        public string Word { get { return _word; } }

        public Token(string word, int start)
            : base(start, start + word.Length - 1)
        {
            _word = word;
        }

        public bool IsChainElement
        {
            get { return IsWord && _word.Length > 1 && char.IsUpper(_word[0]) && char.IsLower(_word[1]); }
        }

        public bool IsWord
        {
            get { return _word.Length > 0 && _word.Any(Char.IsLetterOrDigit); }
        }

        public bool IsWhiteSpace
        {
            get { return _word.Length > 0 && _word.All(char.IsWhiteSpace); }
        }

        public bool IsPunctuation
        {
            get { return _word.Length > 0 && _word.All(char.IsPunctuation); }
        }

        public char this[int i]
        {
            get { return _word[i]; }
        }

        public static implicit operator string(Token w)
        {
            return w._word;
        }
    }
}
